package cn.cj.erp.serviceimpl.system;

import cn.cj.erp.common.utils.Convert;
import cn.cj.erp.bo.system.SysNoticeUserReadBo;
import cn.cj.erp.service.system.SysNoticeUserReadService;
import cn.cj.erp.serviceimpl.base.ServiceImpl;
import cn.cj.erp.entity.system.SysNoticeUserRead;
import cn.cj.erp.dao.system.SysNoticeUserReadDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 通知公告用户阅读表
 * @author chenjian
 */
@Service
public class SysNoticeUserReadServiceImpl extends ServiceImpl<SysNoticeUserRead, SysNoticeUserReadBo>
        implements SysNoticeUserReadService {
    @Resource
    private SysNoticeUserReadDao sysNoticeUserReadDao;

    @Override
    public SysNoticeUserReadDao getBaseMapper() {
        return sysNoticeUserReadDao;
    }

    @Override
    public SysNoticeUserRead convert2Entity(SysNoticeUserReadBo sysNoticeUserReadBo) {
        return Convert.convert(sysNoticeUserReadBo, SysNoticeUserRead.class);
    }

    @Override
    public SysNoticeUserReadBo convert2Bo(SysNoticeUserRead sysNoticeUserRead) {
        return Convert.convert(sysNoticeUserRead, SysNoticeUserReadBo.class);
    }

    @Override
    public List<SysNoticeUserReadBo> listUserRead(Long userId, List<Long> noticeIds) {
        List<SysNoticeUserRead> list = lambdaQuery()
                .eq(SysNoticeUserRead::getUserId, userId)
                .in(SysNoticeUserRead::getNoticeId, noticeIds)
                .list();
        return convert2BoList(list);
    }

    @Override
    public SysNoticeUserReadBo getUserRead(Long userId, Long noticeId) {
        SysNoticeUserRead entity = lambdaQuery()
                .eq(SysNoticeUserRead::getUserId, userId)
                .eq(SysNoticeUserRead::getNoticeId, noticeId).one();
        return convert2Bo(entity);
    }
}